<%@page import="entities.Application"%>
<%@page import="entities.Category"%>
<%@page import="java.util.Map"%>
<%@page import="entities.AutoSite"%>
<%@page import="java.util.List"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
Application app = (Application) request.getAttribute("app");
List<AutoSite> sites = (List<AutoSite>) request.getAttribute("sites");
Map<String, Category> categories = (Map<String, Category>) request.getAttribute("categories"); 
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<jsp:include page="/admin/layouts/header.jsp" />
    
<script type="text/javascript" src="/admin/js/site_list.js"></script>
<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
var appid = "<%=app.getId()%>";
//-->
</script>
        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li><a href="/admin/appconfig/edit/<%=app.getId()%>">Update Application Config</a></li>
                	<li><a href="/admin/appmapping/list/<%=app.getId() %>">Domain Manager</a></li>
                	<li><a href="/admin/category/list/<%=app.getId()%>">Category Manager</a></li>
                	<li><a href="/admin/article/list/<%=app.getId()%>">Article Manager</a></li>
                	<li class="current"><a href="/admin/site/list/<%=app.getId()%>">List Sites</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
                	<jsp:include page="/admin/elements/message_box.jsp" />
                	
                	<div class="">
                		<a class="btn btn_world" href="/admin/site/add/<%=app.getId()%>"><span>New Auto Site</span></a>
                	</div>
                	<br />
                
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>List Site</span></h2>
	                </div>
	                
	                <div class="tableoptions">
	                    <select class="radius3 action-value">
	                    	<option value="status_active">Change to Status Active</option>
	                        <option value="status_inactive">Change to Status Inactive</option>
	                        <option value="delete">Delete all selected</option>
	                    </select> &nbsp;
	                    <button class="radius3 apply-change">Apply</button>
	                </div>
	                
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Sitemaps</th>
	                            <th class="head0">Status</th>
	                            <th class="head1">Time Schedule</th>
	                            <th class="head0">Category</th>
	                            <th class="head1">Author</th>
	                            <th class="head0">Action</th>
	                        </tr>
	                    </thead>
	                    <tfoot>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Sitemaps</th>
	                            <th class="head0">Status</th>
	                            <th class="head1">Time Schedule</th>
	                            <th class="head0">Category</th>
	                            <th class="head1">Author</th>
	                            <th class="head0">Action</th>
	                        </tr>
	                    </tfoot>
	                    <tbody>
	                    	<% for (int i = 0; i < sites.size(); i++) { %>
	                        <tr>
	                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=URLEncoder.encode(sites.get(i).getId())%>"></span></td>
	                            <td><%=sites.get(i).getUrl() %></td>
	                            <td class="center">
	                            	<%
									switch (sites.get(i).getStatus()) {
										case 0: 
											%>Inactive<%
											break;
										case 1:
											%>Active<%
											break;
										default:
											break;
									}
									%>
	                            </td>
	                            <td class="center">
	                            	<%
									switch (sites.get(i).getScheduleSite()) {
										case 60: 
											%>1 hour<%
											break;
										case 120:
											%>2 hours<%
											break;
										case 180:
											%>3 hours<%
											break;
										case 360:
											%>6 hours<%
											break;
										case 720:
											%>12 hours<%
											break;
										case 1080:
											%>18 hours<%
											break;
										case 1440:
											%>24 hours<%
											break;
										default:
											break;
									}
									%>
	                            </td>
	                            <td class="center">
	                            	<% if (categories.get(sites.get(i).getCategory()) != null) { %>
	                            		<%=categories.get(sites.get(i).getCategory()).getName() %>
	                            	<% } %>
	                            </td>
	                            <td class="center">
	                            	<%=sites.get(i).getCreator() %>
	                            </td>
	                            <td class="center">
									<a title="Edit Site" href="/admin/site/edit/<%=URLEncoder.encode(sites.get(i).getId())%>/<%=app.getId() %>" class="edit">
										Edit
									</a>&nbsp;
									<a title="Remove Site" href="/admin/site/delete/<%=URLEncoder.encode(sites.get(i).getId())%>/<%=app.getId() %>" id="action_del" class="delete">
										Delete
									</a>
								</td>
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table>
	                <!-- paginate -->
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                	<% if (prevPage) { %>
							<a class="previous paginate_button" id="dyntable_previous" href="<%=paginator.getPrev()%>">Previous</a>
						<% } else { %>
							<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Previous</span>
						<% } %>
						<% if (nextPage) { %>
							<a class="next paginate_button" id="dyntable_next"  href="<%=paginator.getNext()%>">Next</a>
						<% } else { %>
							<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Next</span>
						<% } %>
	                </div>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp" />
            
        </div><!--maincontent-->
        
<jsp:include page="/admin/layouts/footer.jsp" />